package com.ftu.swt.basic4;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class UsingButton {
    public static void main(String[] args) {
        Display display = Display.getDefault();
        Shell shell1 = new Shell(display);
        shell1.setText("shell1");
        shell1.setSize(400, 400);
        
        Image image = display.getSystemImage(SWT.ICON_QUESTION);
//        final Button button = new Button(shell1, SWT.NONE);
//        Button button = new Button(shell1, SWT.RADIO);
        final Button button = new Button(shell1, SWT.CHECK);
//        Button button = new Button(shell1, SWT.TOGGLE);
        shell1.setImage(image);
        button.setImage(image);
        button.setText("Dispose Display");
        button.setBounds(10, 10, 160, 20);
        button.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                if(button.getSelection()) {
                    System.out.println("Button seledted");
                }
            }
        });
        
        shell1.open();
        while(!shell1.isDisposed()) {
            if(!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
        
    }

}
